<template>
	<view>
		<scroll-view scroll-y class="public-scroll-view">
			<view class="storage-container">
				<button type="default" @click="setStorages()">setStorages</button>
				<button type="primary" @click="getStorages()">getStorages</button>
				<button type="default" @click="getStorageInfo()">getStorageInfo</button>
				<button type="warn" plain="true" @click="removeStorage()">removeStorage</button>
				<button type="warn" @click="clearStorage()">clearStorage</button>
				
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			setStorages(){
				uni.setStorage({
					data:"林勇琪",
					key:"nick",
					success() {
						console.log("缓存成功");
					},
					fail() {
						console.log("缓存失败");
					}
				})
			},
			getStorages(){
				uni.getStorage({
					key:"nick",
					success(res) {
						console.log("获取缓存成功:"+res.data);
					},
					fail() {
						console.log("获取缓存失败");
					}
				})
			},
			getStorageInfo(){
				uni.getStorageInfo({
					success(res) {
						console.log("获取缓存keys成功:"+res.keys+res.datas);
					}
				})
			},
			removeStorage(){
				uni.removeStorage({
					key:"nick",
					success() {
						console.log("删除缓存成功");
					},
					fail() {
						console.log("删除缓存失败");
					}
				})
			},
			clearStorage(){
				uni.clearStorage();
				console.log("清除缓存成功")
			}
		}
	}
</script>

<style>
.storage-container{
	padding-top: 30rpx;
	padding-bottom: 30rpx;
	width: 100%;
	display: flex;
	flex-direction: column;
	justify-content: center;
}
	
.storage-container>button{
	width: 80%;
	margin-top: 20rpx;
}
</style>
